package com.csaba.connector.bha.model;

import com.csaba.connector.bha.SimpleNodeHelper;
import com.csaba.connector.model.Amount;
import com.csaba.connector.model.Customer;
import com.ind.simplenode.SimpleNode;

public class BHACurrentAccount extends BHAAccount
{
	private static final long serialVersionUID = 6064126976964014301L;

	private String branch;
	private String customerId;
	private String suffix;

	public BHACurrentAccount()
	{
		super();
	}

	public BHACurrentAccount( final Customer customer, final SimpleNode properties )
	{
		super(customer, properties);

		//set base fields
		setNumber(SimpleNodeHelper.getAndRemove(properties, "accountGiro1") + "-"
				+ SimpleNodeHelper.getAndRemove(properties, "accountGiro2") + "-"
				+ SimpleNodeHelper.getAndRemove(properties, "accountGiro3"));
		setIBAN(SimpleNodeHelper.getAndRemove(properties, "iBAN"));
		setName(null);
		final String type = SimpleNodeHelper.getAndRemove(properties, "commissionType.text");
		setType(type);

		final String available = SimpleNodeHelper.getAndRemove(properties, "availableBalance");
		final String booked = SimpleNodeHelper.getAndRemove(properties, "balanceInAccountCurrency");
		setAvailableBalance(new Amount(Double.valueOf(available), getCurrency()));
		setBookedBalance(new Amount(Double.valueOf(booked), getCurrency()));

		branch = SimpleNodeHelper.getAndRemove(properties, "branch");
		customerId = SimpleNodeHelper.getAndRemove(properties, "customerId");
		suffix = SimpleNodeHelper.getAndRemove(properties, "suffix");
		properties.add("internalAccountNumber", branch + "-" + customerId + "-" + suffix);

		//set meaningful fields

		SimpleNodeHelper.setAmountProperty(this, properties, "balanceInBaseCurrency", getBank().getBaseCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "blockedAmount", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "lastCloseBalance", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "nextDayNetto", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "nextNextDayNetto", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "overdraft", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "shadowCredit", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "shadowDebit", getCurrency());

		//set remaining
		//SimpleNodeHelper.loadProperties(this, properties);
	}

	/* 
	CURRENT ACCOUNTS
		.response.accounts[2].accountGiro1 = 'xxxxxxxx'
		.response.accounts[2].accountGiro2 = 'xxxxxxxx'
		.response.accounts[2].accountGiro3 = 'xxxxxxxx'
		.response.accounts[2].availableBalance = '#0.00'
	.response.accounts[2].balanceCheckType.code = 'MI'
	.response.accounts[2].balanceCheckType.text = '�n�ll� sz�mla (minimum f�ggv�ny)'
		.response.accounts[2].balanceInAccountCurrency = '#0.00'
		.response.accounts[2].balanceInBaseCurrency = '#0.00'
		.response.accounts[2].blocked = 'false'
		.response.accounts[2].blockedAmount = '#0.00'
	.response.accounts[2].blockedState = 'N'
	.response.accounts[2].branch = 'xxxx'
		.response.accounts[2].closed = 'false'
	.response.accounts[2].closedState = 'N'
	.response.accounts[2].commissionType.code = 'CSA'
	.response.accounts[2].commissionType.text = 'aaaaaaaaaaaaaaaaaaaa'
		.response.accounts[2].currency = 'HUF'
		.response.accounts[2].currentAccount = 'true'
	.response.accounts[2].customerId = 'xxxxxx'
	.response.accounts[2].cycleCounter = '0'
		.response.accounts[2].iBAN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx'
		.response.accounts[2].lastCloseBalance = '#0.00'
	.response.accounts[2].name = 'X Y'
		.response.accounts[2].nextDayNetto = '#0.00'
		.response.accounts[2].nextNextDayNetto = '#0.00'
		.response.accounts[2].noCashierDeposit = 'false'
		.response.accounts[2].noCashierWithdrawal = 'false'
		.response.accounts[2].overdraft = '#0.00'
		.response.accounts[2].shadowCredit = '#0.00'
		.response.accounts[2].shadowDebit = '#0.00'
	.response.accounts[2].suffix = 'xxx'
	.response.accounts[2].technical = 'false'
	.response.accounts[2].type = 'NO'
	*/

	/**
	 * Checks the branch, customerId and suffix attributes of the node, 
	 * and compares to its own values.
	 * @param node
	 * @return true, if the node describing an account is equivalent to this account.
	 */
	public boolean equalsNode( final SimpleNode node )
	{
		final boolean branchEquals = branch.equals(node.getString("branch"));
		final boolean customerIdEquals = customerId.equals(node.getString("customerId"));
		final boolean suffixEquals = suffix.equals(node.getString("suffix"));
		return branchEquals && customerIdEquals && suffixEquals;
	}

	public String getBranch()
	{
		return branch;
	}

	public String getCustomerId()
	{
		return customerId;
	}

	public String getSuffix()
	{
		return suffix;
	}
}
